import axios from "axios";

// 基础url
axios.defaults.baseURL = "http://123.57.109.30:3006";

//根据书名获取图书
/**
 *
 * @param {*} params {bookname：书名}
 * @returns 图书的对象
 */
const getBooks = (params = {}) => {
  return new Promise((resolve, reject) => {
    // 请求
    axios("/api/getbooks", {
      params: params,
      method: "GET",
    })
      .then((res) => {
        resolve(res.data);
      })
      .catch((err) => {
        reject(err);
      });
  });
};
/**
 *
 * @param {*} data
 * @returns
 */
const addBook = (data) => {
  return new Promise((resolve, reject) => {
    axios({
      url: "/api/addbook",
      method: "POST",
      data: {
        appkey: "7250d3eb-18e1-41bc-8bb2-11483665535a",
        ...data,
        // bookname: data.bookname,
        // author: data.author,
        // publisher: data.publisher,
      },
    })
      .then((res) => {
        resolve(res.data);
      })
      .catch((err) => {
        reject(err);
      });
  });
};
export { getBooks, addBook };
